//var projectUpdateChooseCategory = {
//	choose : function() {
//		var yfc = $("#yFristCategroyName").val();
//		var fc = $("#firstCategory").find("a");
//		fc.each(function() {
//			var tfc = $(this);
//			var vfc = tfc.text();
//			if (vfc == yfc) {
//				tfc.click();
//			}
//		});
//		var ysc = $("#ySecondCategroyName").val();
//		var sc = $("#secondCategory").find("a");
//		sc.each(function() {
//			var tsc = $(this);
//			var vsc = tsc.text();
//			if (vsc == ysc) {
//				tsc.click();
//			}
//		});
//		var ytc = $("#yThirdCategroyName").val();
//		var tc = $("#thirdCategory").find("a");
//		tc.each(function() {
//			var ttc = $(this);
//			var vtc = ttc.text();
//			if (vtc == ytc) {
//				ttc.click();
//			}
//		});
//	}
//};
var selectChoose = {
	choose : function() {
		var yp = $("#yPlan").val();
		var ya = $("#yArea").val();
		$("#plan").val(yp);
		$("#area").val(ya);
	}
};
function deleteUpload(id, type) {
	art.dialog.confirm('确认删除？', function() {
		$.ajax({
			dataType : "json",
			type : "post",
			data : "srcId=" + id + "&srcType=" + type,
			url : "/app/project!deleteUpload",
			success : function(data) {
				backUrl.addCookie(data.state);
				if (data.state == "success") {
					var divName = "";
					switch (type) {
					case 1:
						divName = "srcDocId";
						break;
					case 2:
						divName = "srcImgId";
						break;
					case 3:
						divName = "srcTableId";
						break;
					case 4:
						divName = "srcApprovalId";
						break;
					case 5:
						divName = "srcCheckId";
						break;
					case 6:
						divName = "srcVideoId";
						break;
					case 7:
						divName = "srcOtherId";
						break;
					}
					$("#" + divName + id).remove();
					tipsAlert(data.msg);
				} else if (data.state == "error") {
					errorAlert(data.msg);
				}
			}
		});
	});
}
var projectUpdate = {
	check : function() {
		var f_id = $("#fcCategoryId").attr("fcCategoryId");
		var name = $("#projectName").val();
		var impl = $("#implTime").val();
		var fund = $("#fund").val();
		var mgrDepart = $("#mgrDepart").val();
		var id = $("#projectId").val();

		var fundPlan = $("#fundPlan").val();
		if (checkSC(fundPlan)) {
			errorAlert("资金计划不能含有特殊字符！\n如：“\\”“&”“？”“^”“|”“#”“\"”“'”");
			return false;
		}

		if (!checkValue4(id)) {
			errorAlert("无法修改，请重新刷新页面在修改！");
			return false;
		} else if (!checkValue3(f_id)) {
			errorAlert("请选择一级类别！");
			return false;
		} else if (!checkValue(name)) {
			errorAlert("请填写项目名称！");
			return false;
		} else if (!checkValue(impl)) {
			errorAlert("请填写实施时间！");
			return false;
		} else if (!checkValue4(fund)) {
			errorAlert("请正确填写总投资！");
			return false;
		} else if (!checkValue(mgrDepart)) {
			errorAlert("请填写主管部门！");
			return false;
		} else {
			projectUpdate.update(id, f_id, name, impl, fund, mgrDepart);
		}
	},
	update : function(id, f_id, name, impl, fund, mgrDepart) {// fundPlan plan
		art.dialog({
			id : "updateProjectLoading",
			title : "修改中",
			content : "<img src='/controls/artDialog/skins/icons/loading.gif'>"
					+ "<font color='blue'><strong>修改中，请稍后！</strong></font>",
			lock : true
		});
		var s_id = $("#scCategoryId").attr("scCategoryId");
		var t_id = $("#tcCategoryId").attr("tcCategoryId");

		var fundPlan = $.trim($("#fundPlan").val());
		var build = $("#buildSide").val();
		var plan = $("#plan").val();
		var area = $("#area").val();
		var description = $.trim($("#description").val());
		var remarks = $.trim($("#remarks").val());
		var uuid = $("#updateUuid").val();
		var sign = $("#sign").val();
		$.ajax({
			data : {
				"f_id" : f_id,
				"projectName" : name,
				"implTime" : impl,
				"buildSide" : build,
				"fund" : fund,
				"mgrDepart" : mgrDepart,
				"s_id" : s_id,
				"t_id" : t_id,
				"fundPlan" : fundPlan,
				"plan" : plan,
				"area" : area,
				"remarks" : remarks,
				"description" : description,
				"p_id" : id,
				"sign" : sign,
				"uuid" : uuid
			},
			dataType : "json",
			type : "post",
			url : "/app/project!updateProject",
			success : function(data) {
				art.dialog({
					id : "updateProjectLoading"
				}).close();
				backUrl.addCookie(data.state);
				if (data.state == "success") {
					art.dialog({
						id : "successUpdate",
						icon : 'succeed',
						lock : true,
						content : data.msg,
						button : [ {
							name : '确定',
							callback : function() {
								location.reload();
							},
							focus : true
						} ],
						cancelVal : '取消',
						cancel : true,
					});
				} else if (data.state == "error") {
					errorAlert(data.msg);
				}
			}
		});
	}
};
var onloadProjectUpdate = {
	onload : function() {
		$("#implTime").focus(function() {
			WdatePicker({
				dateFmt : 'yyyy-MM'
			});
		});
		$(".btn").click(function() {
			projectUpdate.check();
		});

		$("#fundPlan").val($.trim($("#fundPlan").val()));
		$("#description").val($.trim($("#description").val()));
		$("#remarks").val($.trim($("#remarks").val()));
		$("#sign").val($.trim($("#sign").val()));

		var f_id = $("#fcCategoryId").attr("fcCategoryId");
		if (null != f_id && 1 != Number(f_id)) {
			var plan = $("#plan option:first").val();
			if (plan == "储备") {
				$("#plan option:first").remove();
			}
		}

		$("#firstCategory").click(function() {
			var f_id = $("#fcCategoryId").attr("fcCategoryId");
			if (null != f_id && 1 != Number(f_id)) {
				var plan = $("#plan option:first").val();
				if (plan == "储备") {
					$("#plan option:first").remove();
				}
			} else {
				var plan = $("#plan option:first").val();
				if (plan != "储备") {
					$("#plan option:first").before("<option value='储备'>储备</option>");
				}
			}
		});
		
//		projectUpdateChooseCategory.choose();
		selectChoose.choose();
	}
};